package com.token.mwallet.db.greendao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.token.mwallet.utils.StringConverter;
import java.util.List;

import com.token.mwallet.db.MangoWallet;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "MANGO_WALLET".
*/
public class MangoWalletDao extends AbstractDao<MangoWallet, Long> {

    public static final String TABLENAME = "MANGO_WALLET";

    /**
     * Properties of entity MangoWallet.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Image = new Property(1, int.class, "image", false, "IMAGE");
        public final static Property WalletType = new Property(2, int.class, "walletType", false, "WALLET_TYPE");
        public final static Property WalletPassword = new Property(3, String.class, "walletPassword", false, "WALLET_PASSWORD");
        public final static Property Hint = new Property(4, String.class, "hint", false, "HINT");
        public final static Property WalletAddress = new Property(5, String.class, "WalletAddress", false, "WALLET_ADDRESS");
        public final static Property PrivateKey = new Property(6, String.class, "privateKey", false, "PRIVATE_KEY");
        public final static Property PublicKey = new Property(7, String.class, "publicKey", false, "PUBLIC_KEY");
        public final static Property Keystore = new Property(8, String.class, "keystore", false, "KEYSTORE");
        public final static Property MnemonicCode = new Property(9, String.class, "mnemonicCode", false, "MNEMONIC_CODE");
        public final static Property Tokens = new Property(10, String.class, "tokens", false, "TOKENS");
    }

    private final StringConverter mnemonicCodeConverter = new StringConverter();
    private final StringConverter tokensConverter = new StringConverter();

    public MangoWalletDao(DaoConfig config) {
        super(config);
    }
    
    public MangoWalletDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"MANGO_WALLET\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"IMAGE\" INTEGER NOT NULL ," + // 1: image
                "\"WALLET_TYPE\" INTEGER NOT NULL ," + // 2: walletType
                "\"WALLET_PASSWORD\" TEXT NOT NULL ," + // 3: walletPassword
                "\"HINT\" TEXT," + // 4: hint
                "\"WALLET_ADDRESS\" TEXT," + // 5: WalletAddress
                "\"PRIVATE_KEY\" TEXT NOT NULL ," + // 6: privateKey
                "\"PUBLIC_KEY\" TEXT," + // 7: publicKey
                "\"KEYSTORE\" TEXT," + // 8: keystore
                "\"MNEMONIC_CODE\" TEXT," + // 9: mnemonicCode
                "\"TOKENS\" TEXT);"); // 10: tokens
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"MANGO_WALLET\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, MangoWallet entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getImage());
        stmt.bindLong(3, entity.getWalletType());
        stmt.bindString(4, entity.getWalletPassword());
 
        String hint = entity.getHint();
        if (hint != null) {
            stmt.bindString(5, hint);
        }
 
        String WalletAddress = entity.getWalletAddress();
        if (WalletAddress != null) {
            stmt.bindString(6, WalletAddress);
        }
        stmt.bindString(7, entity.getPrivateKey());
 
        String publicKey = entity.getPublicKey();
        if (publicKey != null) {
            stmt.bindString(8, publicKey);
        }
 
        String keystore = entity.getKeystore();
        if (keystore != null) {
            stmt.bindString(9, keystore);
        }
 
        List mnemonicCode = entity.getMnemonicCode();
        if (mnemonicCode != null) {
            stmt.bindString(10, mnemonicCodeConverter.convertToDatabaseValue(mnemonicCode));
        }
 
        List tokens = entity.getTokens();
        if (tokens != null) {
            stmt.bindString(11, tokensConverter.convertToDatabaseValue(tokens));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, MangoWallet entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getImage());
        stmt.bindLong(3, entity.getWalletType());
        stmt.bindString(4, entity.getWalletPassword());
 
        String hint = entity.getHint();
        if (hint != null) {
            stmt.bindString(5, hint);
        }
 
        String WalletAddress = entity.getWalletAddress();
        if (WalletAddress != null) {
            stmt.bindString(6, WalletAddress);
        }
        stmt.bindString(7, entity.getPrivateKey());
 
        String publicKey = entity.getPublicKey();
        if (publicKey != null) {
            stmt.bindString(8, publicKey);
        }
 
        String keystore = entity.getKeystore();
        if (keystore != null) {
            stmt.bindString(9, keystore);
        }
 
        List mnemonicCode = entity.getMnemonicCode();
        if (mnemonicCode != null) {
            stmt.bindString(10, mnemonicCodeConverter.convertToDatabaseValue(mnemonicCode));
        }
 
        List tokens = entity.getTokens();
        if (tokens != null) {
            stmt.bindString(11, tokensConverter.convertToDatabaseValue(tokens));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public MangoWallet readEntity(Cursor cursor, int offset) {
        MangoWallet entity = new MangoWallet( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // image
            cursor.getInt(offset + 2), // walletType
            cursor.getString(offset + 3), // walletPassword
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // hint
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // WalletAddress
            cursor.getString(offset + 6), // privateKey
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // publicKey
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // keystore
            cursor.isNull(offset + 9) ? null : mnemonicCodeConverter.convertToEntityProperty(cursor.getString(offset + 9)), // mnemonicCode
            cursor.isNull(offset + 10) ? null : tokensConverter.convertToEntityProperty(cursor.getString(offset + 10)) // tokens
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, MangoWallet entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setImage(cursor.getInt(offset + 1));
        entity.setWalletType(cursor.getInt(offset + 2));
        entity.setWalletPassword(cursor.getString(offset + 3));
        entity.setHint(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setWalletAddress(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setPrivateKey(cursor.getString(offset + 6));
        entity.setPublicKey(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setKeystore(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setMnemonicCode(cursor.isNull(offset + 9) ? null : mnemonicCodeConverter.convertToEntityProperty(cursor.getString(offset + 9)));
        entity.setTokens(cursor.isNull(offset + 10) ? null : tokensConverter.convertToEntityProperty(cursor.getString(offset + 10)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(MangoWallet entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(MangoWallet entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(MangoWallet entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
